<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>订单管理-[[${T(com.b2c.erp.DataConfigObject).getInstance().getSysName()}]]</title>

</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this">订单管理</li>
            <li ><a href="/erp_sales/order_create">手动下单</a></li>
            <li ><a href="/erp_sales/refund_list">退货管理</a></li>
        </ul>
    </div>
    <style>
        .hideAddress{
            width: 300px;
            display: inline-block;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <!-- content starts -->
    <!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" th:action="@{/erp_sales/order_list}">
                <input type="hidden" name="shopId" value="99" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" placeholder="订单编号" class="layui-input" style="width: 200px">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="contactMobile" placeholder="收货人手机号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="buyerUserId" id="buyerUserId">
                                <option value="">客户</option>
                                <option th:each="item:${clientList}" th:value="${item.id}"
                                        th:text="${item.name + item.contact}">
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="type" id="type">
                                <option value="">订单类型</option>
                                <option value="0">外发样品</option>
                                <option value="1">实售订单</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="auditStatus" id="auditStatus">
                                <option value="">确认状态</option>
                                <option value="0">待确认</option>
                                <option value="1">已确认</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
<!--                    <div class="layui-inline">-->
<!--                        <input type="text" name="sku" placeholder="商品SKU" class="layui-input" style="width: 200px">-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" id="startTime" autocomplete="off"
                                   placeholder="yyyy-MM-dd">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" id="endTime" autocomplete="off"
                                   placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                </div>
                <div class="layui-form-item">

                </div>

            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th>ID</th>
                <th>订单号</th>
                <th>下单时间</th>
                <th >商品数量</th>
<!--                <th >退货数量</th>-->
<!--                <th >SKU数量</th>-->
                <th >商品总价</th>
                <th >运费</th>
                <th>客户信息</th>
<!--                <th>收件人</th>-->
                <th>销售类型</th>
                <th>支付信息</th>
                <th>发货信息</th>
<!--                <th>物流信息</th>-->
                <th>确认状态</th>
                <th>退款状态</th>
<!--                <th>订单来源</th>-->
                <th></th>
            </tr>
            <tr th:each="item:${lists}">
                <td th:text="${item.id}"></td>
                <td>
                    <p th:text="${item.orderNum}"></p>
                </td>
                <td>
                    <p th:text="${#dates.format(item.getCreateOn() * 1000, 'yyyy-MM-dd HH:mm:ss')}"></p>
                </td>
                <td >
                    SKU：<span th:text="${item.goodsSpecCount}"></span><br />
                    总数：<span th:text="${item.goodsCount}"></span>
                </td>
<!--                <td >-->
<!--                    <b th:text="${item.refundQuantity}"></b>&nbsp;-->
<!--                    <a th:if="${item.refundQuantity > 0}" th:href="@{/sales/refundList(type=${item.saleType},orderNum=${item.orderNum})}" target="_blank">查看</a>-->
<!--                </td>-->
<!--                <td th:text="${item.goodsSpecCount}"></td>-->
                <td th:text="${item.goodsTotalAmount}"></td>
                <td th:text="${item.shippingFee}"></td>
                <td >
                    <p>客户：<span th:text="${item.developerName}"></span></p>

                    <p>收件人：<span th:text="${item.contactPerson}"></span>&nbsp;<span th:text="${item.contactMobile}"></span></p>
                    <span class="hideAddress" th:title="${item.address}" th:text="${'收件地址：'+item.address}"></span>
                </td>
<!--                <td ><span th:text="${item.contactPerson}"></span>&nbsp;<span th:text="${item.contactMobile}"></span><br/>-->

<!--                    <span class="hideAddress" th:title="${item.address}" th:text="${item.address}"></span>-->
<!--                </td>-->

                <td>
                    <p th:if="${item.saleType == 0 }">外发样品</p>
                    <p th:if="${item.saleType == 1 }">实售订单</p>
                </td>
                <td>
                    <span  th:text="${T(com.b2c.entity.enums.erp.EnumSalesOrderPayStatus).getName(item.payStatus)}"></span><br />
                    <span th:if="${item.payStatus > 0 }" th:text="${#dates.format(item.payTime * 1000, 'yyyy-MM-dd HH:mm:ss')}"></span>
                </td>
                <td>
                    <b th:text="${T(com.b2c.entity.enums.erp.EnumErpOrderSendStatus).getName(item.deliveredStatus)}"></b>
                    <br />
                    <span th:if="${item.deliveredStatus ==4}" >
                        <span th:text="${#dates.format(item.deliveredTime * 1000, 'yyyy-MM-dd HH:mm:ss')}"></span><br/>
                       <span th:text="${item.logisticsCompany}"></span><br/>
                    <span th:text="${item.logisticsCode}"></span>
                    </span>
                </td>
<!--                <td>-->

<!--                </td>-->
                <td>
                    <span  th:text="${T(com.b2c.entity.enums.erp.EnumErpOrderStatus).getName(item.status)}"></span><br />
                    <b th:if="${item.auditStatus == 0 && item.status == T(com.b2c.entity.enums.erp.EnumErpOrderStatus).WaitSend.getIndex()}" style="color: red">待确认</b><br />
                    <span th:if="${item.auditStatus == 1 }">已确认</span><br />


                </td>
                <td >
                    <span th:if="${item.status == T(com.b2c.entity.enums.erp.EnumErpOrderStatus).REFUND.getIndex()}" style="color: red">已退款</span>
                </td>
<!--                <td th:text="${item.shopName}"></td>-->
                <td>
                    <a th:href="@{/erp_sales/order_detail(id=${item.getId()},shopId=${shopId})}">查看详情</a>

                    <a class="cancel_order" href="javascript:;" th:if="${item.getAuditStatus() == 0 && (item.status ==  T(com.b2c.entity.enums.erp.EnumErpOrderStatus).WaitSend.getIndex() || item.status ==  T(com.b2c.entity.enums.erp.EnumErpOrderStatus).WaitAudit.getIndex() ) && item.shopId == 99}"
                       th:attr="order-id=${item.getId()}">取消订单</a>
                    <br />

                    <a class="layui-btn layui-btn-xs layui-btn-normal" style="color: #fff"
                       th:if="${item.getAuditStatus() == 0 && item.status ==  T(com.b2c.entity.enums.erp.EnumErpOrderStatus).WaitSend.getIndex() && item.shopId == 99}"
                       th:href="@{/erp_sales/order_detail(id=${item.getId()})}">确认订单</a>

                    <a th:if="${item.status >=  T(com.b2c.entity.enums.erp.EnumErpOrderStatus).Delivered.getIndex() && item.shopId == 99}"
                       th:href="@{/erp_sales/refundApply(id=${item.getId()},shopId =99)}">申请退货</a>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>


    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;

        //计算天数差的函数，通用
        function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2019-3-12格式
            var aDate, oDate1, oDate2, iDays
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
            return iDays
        }

        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            //下拉框默认值
            // var shopId = '[[${shopId}]]';
            // if(shopId!='')
            //     $("#shopId").val(shopId);
            var auditStatus = '[[${auditStatus}]]';
            if(auditStatus!='')
                $("#auditStatus").val(auditStatus);

            var buyerUserId = '[[${buyerUserId}]]';
            if(buyerUserId!='')
                $("#buyerUserId").val(buyerUserId);

            var status = '[[${status}]]';
            if(status!='')
                $("#status").val(status);

            var saleType = '[[${saleType}]]';
            if(saleType!='')
                $("#type").val(saleType);

            form.render();
            $(function () {

            })
        });
        //取消订单
        $(".cancel_order").click(function () {
            if(confirm("确定要取消订单吗？")){
                var orderId =$(this).attr("order-id");
                $.ajax({
                    url: "/ajax_order_confirm/order_cancel",
                    type: "POST",
                    dataType: "JSON",
                    contentType: 'application/json',
                    data: JSON.stringify({orderId:orderId}),
                    success: function (res) {
                        if (res.code == 0) {
                            alert("取消成功！");
                            window.location.reload();
                        } else {
                            alert(res.msg);
                        }


                    }
                })
            }
        })
        //展开查看更多
        $(".display_zk").click(function () {
            var obj = $(this);
            $(this).siblings(".display").each(function () {
                $(this).show();
            });
            obj.remove();
        })

    </script>


</div>
</body>
</html>
